package horncomb.bpm.task.entity;

import horncomb.bpm.task.core.TaskInstanceEntity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang.StringUtils;

/**
 * @author Daniel
 */
@Entity
@Table(name = "BPM_TASKINST")
public class DefaultTaskInstanceEntity implements Serializable,
		TaskInstanceEntity {
	private static final long serialVersionUID = 8907646324873385569L;
	private String tokenId;
	private String id;
	private String name;
	private String actor;
	private String candidateStr;
	private boolean holding;
	private boolean hiding;

	private Date createdDate;
	private Date startedDate;
	private Date endDate;

	private String type;

	/**
	 * @return the tokenId
	 */
	@Column(name = "TOKEN_")
	public String getTokenId() {
		return tokenId;
	}

	/**
	 * @param tokenId
	 *            the tokenId to set
	 */
	public void setTokenId(String tokenId) {
		this.tokenId = tokenId;
	}

	/**
	 * @return the id
	 */
	@Id
	@Column(name = "ID_")
	public String getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * @return the name
	 */
	@Column(name = "NAME_")
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the actor
	 */
	@Column(name = "ACTOR_")
	public String getActor() {
		return actor;
	}

	/**
	 * @param actor
	 *            the actor to set
	 */
	public void setActor(String actor) {
		this.actor = actor;
	}

	/**
	 * @return the candidate
	 */
	public String[] getCandidate() {
		return candidateStr == null ? null : candidateStr.substring(1,
				candidateStr.length() - 2).split("|");
	}

	/**
	 * @param candidate
	 *            the candidate to set
	 */
	public void setCandidate(String[] candidate) {
		if (candidate != null) {
			this.candidateStr = '|' + StringUtils.join(candidate, "|") + '|';
		} else {
			this.candidateStr = null;
		}
	}

	@Column(name = "CANDIDATE_")
	public String getCandidateStr() {
		return this.candidateStr;
	}

	/**
	 * @param candidateStr
	 *            the candidateStr to set
	 */
	public void setCandidateStr(String candidateStr) {
		this.candidateStr = candidateStr;
	}

	/**
	 * @return the createdDate
	 */
	public Date getCreatedDate() {
		return createdDate;
	}

	/**
	 * @param createdDate the createdDate to set
	 */
	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	/**
	 * @return the startedDate
	 */
	@Column(name = "START_")
	public Date getStartedDate() {
		return startedDate;
	}

	/**
	 * @param startedDate
	 *            the startedDate to set
	 */
	public void setStartedDate(Date startedDate) {
		this.startedDate = startedDate;
	}

	/**
	 * @return the endDate
	 */
	@Column(name = "END_")
	public Date getEndDate() {
		return endDate;
	}

	/**
	 * @param endDate
	 *            the endDate to set
	 */
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	/**
	 * @return the holding
	 */
	@Column(name = "HOLDING_")
	public boolean isHolding() {
		return holding;
	}

	/**
	 * @param holding
	 *            the holding to set
	 */
	public void setHolding(boolean holding) {
		this.holding = holding;
	}

	public boolean isHiding() {
		return hiding;
	}

	public void setHiding(boolean hiding) {
		this.hiding = hiding;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
}
